home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: File Open Problem - Please provide clues
- Date: 30 Mar 1996 22:25 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <30MAR199622252431@erich.triumf.ca>
- References: <4jkq8h$1it6@useneta1.news.prodigy.com>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4jkq8h$1it6@useneta1.news.prodigy.com>, DPMU12A@prodigy.com (Steve Bailey) writes...
- >
- >Hi I'm having problems with opening files which are named
- >after simple numbers:
- >2
- >5, etc.
- >The reason for naming them this way is because I'm writing a
- >program in C that increments a number, and then attempts to
- >open the file that's actually named by that number.
- >I get mismatched type errors when using FOPEN:
- > int num;
- > filepointer = FOPEN(num,"r"); or
- > filepointer = FOPEN("num","r");
-
- don't know about FOPEN(), but fopen() requires a string as it's first argument.
-
- Try something like:
- char fnstring[20];
- int num;
- ....
- sprintf(fnstring, "%d", num);
- if((fp = fopen(fnstring, "r") == NULL)
- /* error...*/
-
- > I was going to name the files:
- > 0.txt, 1.txt, 2.txt,
- > and so forth, but this was even trickier with the string
- >concatenating, (attached ".txt" to it) etc.. so the files
- >are named after numbers simply..
-
- This shold be quite trivial, now that you've seen what I did above...
-
- sprintf(fnstring,"%d.txt", num);
-
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-
-
-
-
-
-
-
-
-
-